﻿namespace Cfg.Proxies
{
    public abstract class ProxyBase
    {
        internal const string CurrentScopeKey = "cfg.proxies.currentContext";
        public string InternalNamespace  { get; set; }

        protected T GetValue<T>(T originalvalue, string key)
        {
            var fullKey = InternalNamespace == null ? key : string.Format("{0}.{1}", InternalNamespace, key);
            var scope = WebSafeCallContext.GetData(CurrentScopeKey) as ICfgScope;
            if (scope != null && scope.HasValue(fullKey))
            {
                return scope.GetValue<T>(fullKey);
            }

            return originalvalue;
        }
    }
}